﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Security.Principal;
using System.ServiceModel;
using System.ServiceModel.Activation;

using SBPweb.PROvibe.Server.Library.Hosting;
using SBPweb.PROvibe.Server.Library.Services;

using SBPweb.PROvibe.Server.Modules.UserProvider.Contracts;

using SBPweb.PROvibe.Shared.Library.Actors;
using SBPweb.PROvibe.Shared.Library.Components;

namespace SBPweb.PROvibe.Server.Modules.UserProvider
{

    [ServiceBehavior(Name = "IUserProviderService", Namespace = Contracts.Constants.Services.UserProviderNamespace)]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class UserProviderService : ServiceBase<IUserProviderService>, IUserProviderService
    {

        #region Fields

        #endregion

        #region Constructor logic

        public UserProviderService()
            : base(null)
        {
        }

        public UserProviderService(IModule parentModule)
            : base(parentModule)
        {
        }

        #endregion

        #region Properties

        public override string Name
        {
            get
            {
                return "UserProviderService";
            }
        }

        #endregion

        #region Operations

        [OperationBehavior(Impersonation = ImpersonationOption.Required)]
        public User GetCurrentUser()
        {
            return GetUser(OperationContext.Current.ServiceSecurityContext.PrimaryIdentity);
        }

        [OperationBehavior(Impersonation = ImpersonationOption.Required)]
        public bool IsMemberOfRole(User user, string roleName)
        {
            ///TODO: implement membership check
            return true;
        }

        #endregion

        #region Methods

        protected override void OnInitialize()
        {
            //IDataProviderService isps = this.Parent.PublicServices.Get<IDataProviderService>();
        }

        protected override void OnTerminate()
        {
        }

        public User GetUser(IIdentity identity)
        {
            return new User(identity);
        }

        #endregion

    }

}